<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(k) {
      if (k % 2 === 0 || k % 5 === 0) {
        return -1;
      }
      let resid = 1 % k, len = 1;
      while (resid !== 0) {
        resid = (resid * 10 + 1) % k;
        len++;
      }
      return len;
    };
    console.log(arr(2));
  </script>
</body>

</html>